package com.itheima.web;

import com.itheima.pojo.PageBean;
import com.itheima.pojo.User;
import com.itheima.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/findUserByPageServlet")
public class FindUserByPageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //拿到当前的页码
        String currentPage = request.getParameter("currentPage");

        //拿到每页显示的条数
        String pageSize = request.getParameter("pageSize");

        if (currentPage == null || currentPage.equals("")) {
            currentPage = "1";
        }
        if (pageSize == null || pageSize.equals("")) {
            pageSize = "5";
        }

        PageBean<User> pb = new UserService().findUserByPage(currentPage, pageSize);

        System.out.println(pb);

        //将用户存储到域对象中
        request.setAttribute("pb", pb);

        //请求转发到list.jsp页面中
        request.getRequestDispatcher("/list.jsp").forward(request, response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
